﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class views_uchome_promotion_product : System.Web.UI.UserControl
{
    DataProvider datapro = new DataProvider();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            load_product();
            lbtitle.Text = "Khuyến mãi";
        }
    }
    public void load_product()
    {
        DataTable dt_product_new = datapro.sp_select("sp_view_productview_promotions");

        string strproduc = "<ul class=\"products\" style=\"margin: 0pt; padding: 0pt; position: relative; \">";
        string strli = @"<li class='first' style=' float: left; width: 150px; height: 227px;'>
                            <a href='{0}' class='product' title='#' alt='#' rel='product-results'>
                                <span class='figure'>
                                    <img width='150' src='{1}'>
                                    {2}
                                </span>
                                <h2 style='height:16px;'>
                                    {3}
                                </h2>
                                <div class='price-details'>
                                    <span class='price-new'>
                                        {4}đ</span>
                                    <span style='float: none; display: block' class='price-old'>
                                        {5}</span>
                                </div>
                                <div class='view-sells'>
                                    <span class='views'>
                                        View : {6}</span>
                                    <span style='float: none; display: block' class='sells'>
                                        Sell : {7}</span>
                                </div>
                            </a>
                        </li>";
        float discount;
        string strdiscount = "";
        string strprice = "";
        string stroldprice = "";
        for (int i = 0; i < 8 && i < dt_product_new.Rows.Count; i++)
        {
            strprice = dt_product_new.Rows[i]["price"].ToString();
            strdiscount = "";
            if (dt_product_new.Rows[i]["discount"].ToString().Trim() != "")
            {
                discount = float.Parse(dt_product_new.Rows[i]["discount"].ToString().Trim());
                strdiscount = string.Format("<span class=\"promotion_tag\" >{0}%</span>",discount);
                stroldprice = dt_product_new.Rows[i]["price"].ToString();
                strprice = ((int.Parse(dt_product_new.Rows[i]["price"].ToString()) * discount) / 100).ToString();
            }

            strproduc = strproduc + string.Format(strli,
                "index.aspx?proid=" + dt_product_new.Rows[i].ToString(),
                "images/products/" + dt_product_new.Rows[i]["image"].ToString().Trim(),
                strdiscount,
                dt_product_new.Rows[i]["productname"].ToString(),
                strprice,
                stroldprice,
                dt_product_new.Rows[i]["totalview"].ToString(),
                dt_product_new.Rows[i]["totalsell"].ToString());
        }
        lbproductview.Text = strproduc + "</ul>";
    }
}